package com.intretech.umsin.common.service;

import com.intretech.umsin.common.config.ParseDictProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version V1.0
 * @ClassName: ParseDictServiceFactory
 * @Description: 功能描述
 * @author: 李启联
 * @date: 2022-6-8 19:43
 * @Copyright: Copyright (c) 2022
 */
@Service
public class ParseDictServiceFactory {

    @Autowired
    private ParseDictProperties parseDictProperties;

    protected Map<String, ParseDictService> parseDictServiceMap = new HashMap<>();

    public ParseDictServiceFactory(List<ParseDictService> parseDictServices){
        String className ;
        for (ParseDictService service : parseDictServices) {
            className = service.getClass().getTypeName();
            if(className.indexOf('$') > 0){
                className = className.substring(0,className.indexOf('$'));
            }
            parseDictServiceMap.put(className,service);
        }
    }

    public ParseDictService createParseDictService(){
        ParseDictService recordLogsService = parseDictServiceMap.get(parseDictProperties.getServiceClassName());
        return recordLogsService;
    }


}